
#ifndef __MAX31856_H
#define __MAX31856_H

/* 包含头文件 ----------------------------------------------------------------*/
#include "stm32g4xx_hal.h"
#include "main.h"
/* 类型定义 ------------------------------------------------------------------*/
/* 宏定义 --------------------------------------------------------------------*/
#define MAX31856_SPIx                SPI2
#define MAX31856_SPIx_CLK_ENABLE()    __HAL_RCC_SPI2_CLK_ENABLE()
#define MAX31856_GPIO_CLK_ENABLE()   __HAL_RCC_GPIOB_CLK_ENABLE()
#define MAX31856_CS_Pin              GPIO_PIN_0
#define MAX31856_CS_GPIO_Port        GPIOB
#define MAX31856_SCK_Pin             GPIO_PIN_13
#define MAX31856_SCK_GPIO_Port       GPIOB
#define MAX31856_MISO_Pin            GPIO_PIN_14
#define MAX31856_MISO_GPIO_Port      GPIOB
#define MAX31856_MOSI_Pin            GPIO_PIN_15
#define MAX31856_MOSI_GPIO_Port      GPIOB


#define MAX31856_RDY_Pin             GPIO_PIN_0
#define MAX31856_RDY_GPIO_Port       GPIOB

#define MAX31856_CS_ENABLE()         HAL_GPIO_WritePin(MAX31856_CS_GPIO_Port,MAX31856_CS_Pin,GPIO_PIN_RESET)
#define MAX31856_CS_DISABLE()        HAL_GPIO_WritePin(MAX31856_CS_GPIO_Port,MAX31856_CS_Pin,GPIO_PIN_SET)

#define   Cold_Junction_Resolution    0.015625
#define   TC_Resolution               0.0078125   
   
#define  Stop_Conversion_Bit        (uint8_t) 0x3F
#define  One_Shot_Conversion        (uint8_t) 0x40
#define  Automatic_Conversion       (uint8_t) 0x80 
   
#define  OC_Fault_Disable_Bit       (uint8_t) 0xCF 
#define  OC_Fault_Enable_1          (uint8_t) 0x10
#define  OC_Fault_Enable_2          (uint8_t) 0x20
#define  OC_Fault_Enable_3          (uint8_t) 0x30
   
#define  CJ_Sensor_Enable_Bit       (uint8_t) 0xF7
#define  CJ_Sensor_Disable          (uint8_t) 0x08
   
#define  Comparator_Mode_Bit        (uint8_t) 0xFB
#define  Interrupt_Mode             (uint8_t) 0x04

#define  Fault_Clear                (uint8_t) 0x02

#define  NRF_60Hz_Bit               (uint8_t) 0xFE
#define  NRF_50Hz                   (uint8_t) 0x01
   
   
#define Average_1_Bit               (uint8_t) 0x0F
#define Average_2                   (uint8_t) 0x10
#define Average_4                   (uint8_t) 0x20
#define Average_8                   (uint8_t) 0x30
#define Average_16                  (uint8_t) 0x40  
   
#define TC_TypeB_Bit                (uint8_t) 0xF0
#define TC_TypeE                    (uint8_t) 0x01
#define TC_TypeJ                    (uint8_t) 0x02
#define TC_TypeK                    (uint8_t) 0x03
#define TC_TypeN                    (uint8_t) 0x04
#define TC_TypeR                    (uint8_t) 0x05
#define TC_TypeS                    (uint8_t) 0x06
#define TC_TypeT                    (uint8_t) 0x07
#define VM_Gain8                    (uint8_t) 0x80
#define VM_Gain16                   (uint8_t) 0xC0

   
   
#define CJ_High_Fault_Mask          (uint8_t)0x20
#define CJ_Low_Fault_Mask           (uint8_t)0x10
#define TC_High_Fault_Mask          (uint8_t)0x08
#define TC_Low_Fault_Mask           (uint8_t)0x04
#define OVUV_Fault_Mask             (uint8_t)0x02
#define Open_Fault_Mask             (uint8_t)0x01
#define ALL_Fault_Mask              (uint8_t)0x3F
#define No_Fault_Mask               (uint8_t)0x00
   
#define CJ_Range_Fault              (uint8_t)0x80
#define TC_Range_Fault              (uint8_t)0x40
#define CJHIGH_Fault                (uint8_t)0x20
#define CJLOW_Fault                 (uint8_t)0x10
#define TCHIGH_Fault                (uint8_t)0x08
#define TCLOW_Fault                 (uint8_t)0x04
#define OVUV_Fault                  (uint8_t)0x02
#define OPEN_Fault                  (uint8_t)0x01
#define NO_Fault                    (uint8_t)0x00   

/* 扩展变量 ------------------------------------------------------------------*/
extern SPI_HandleTypeDef hspi_MAX31856;

/* 函数声明 ------------------------------------------------------------------*/
void MX_MAX31856_SPI_Init(void);

void MAX31856_Init(void);
void MAX31856_Stop_Conversion(void);
void MAX31856_Start_Conversion(uint8_t uch_conversion_mode);
void MAX31856_Disable_Oc_Fault_Detection(void);
void MAX31856_Set_Oc_Fault_Detection(uint8_t uch_oc_fault_enable);
void MAX31856_Clear_Fault_Status(void);

void MAX31856_Write_Register(uint8_t uch_register_address, uint8_t uch_register_value);
uint8_t MAX31865_Read_Register(uint8_t uch_register_address);
void MAX31856_Read_Nregisters(uint8_t uch_register_address, uint8_t *uch_buff,uint8_t uch_nBytes);
  
#endif  /* __BSP_SPIWEIGHT_H__ */

/******************* (C) COPYRIGHT 2015-2020 硬石嵌入式开发团队 *****END OF FILE****/



